package com.wdf.project03.controller;

import com.wdf.project03.pojo.Emp;
import com.wdf.project03.pojo.PageBean;
import com.wdf.project03.pojo.Result;
import com.wdf.project03.service.EempService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EempService empService;
    @GetMapping
    private Result listEmps(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            String name, Short gender,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        PageBean  pageBean = empService.page(page,pageSize,name,gender,begin,end);
        return  Result.success(pageBean);
    }
    @DeleteMapping("/{id}")
    private Result deleteById(@PathVariable Integer id){
        empService.deleteById(id);
        return  Result.success();
    }
    @PutMapping()
    private Result updateById(@RequestBody Emp emp){
        empService.updateById(emp);
        return  Result.success();
    }
    @GetMapping("/{id}")
    private Result updateById(@PathVariable Integer id){
        Emp emp =  empService.selectById(id);
        return Result.success(emp);
    }
    @PostMapping
    private Result insert(@RequestBody Emp emp){
        empService.insert(emp);
        return Result.success(emp);
    }
}
